package com.heima.article.listen;


import com.heima.model.common.constants.article.HotArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class HotArticleScoreListener {

    @Autowired
    StringRedisTemplate redisTemplate;

    @RabbitListener(queuesToDeclare = @Queue(HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_QUEUE))
    public void hotArticleMstHandler(String behaviorDtoMsg){
        log.info("接收到新增行为消息 {}",behaviorDtoMsg);
        // 直接使用redis的list结构 rpush 存入
        redisTemplate.opsForList().rightPush(HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_LIST,behaviorDtoMsg);
        log.info("将 行为消息存入redis中的list集合中 {}",behaviorDtoMsg);

    }
}
